﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.AsymmetricCryptoSession
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Security.Principal;

namespace Microsoft.InfoCards
{
  internal class AsymmetricCryptoSession : CryptoSession
  {
    private RSACryptoServiceProvider m_provider;

    public AsymmetricCryptoSession(
      Process process,
      DateTime expirationTime,
      WindowsIdentity identity,
      RSACryptoServiceProvider key)
      : base(process, expirationTime, identity, (object) key, CryptoSession.SessionType.Asymmetric)
    {
      this.m_provider = key;
    }

    protected override void OnWrite(BinaryWriter bwriter)
    {
      bwriter.Write(this.m_provider.KeySize);
      Utility.SerializeString(bwriter, this.m_provider.KeyExchangeAlgorithm);
      Utility.SerializeString(bwriter, this.m_provider.SignatureAlgorithm);
    }

    protected override void OnDispose()
    {
      this.m_provider.Clear();
      ((IDisposable) this.m_provider).Dispose();
      this.m_provider = (RSACryptoServiceProvider) null;
    }

    public byte[] Encrypt(bool fOAEP, byte[] inData)
    {
      this.ThrowIfDisposed();
      return this.m_provider.Encrypt(inData, fOAEP);
    }

    public byte[] Decrypt(bool fOAEP, byte[] inData)
    {
      this.ThrowIfDisposed();
      return this.m_provider.Decrypt(inData, fOAEP);
    }

    public byte[] SignHash(byte[] hash, string hashAlgOid)
    {
      this.ThrowIfDisposed();
      return this.m_provider.SignHash(hash, hashAlgOid);
    }

    public bool VerifyHash(byte[] hash, string hashAlgOid, byte[] sig)
    {
      this.ThrowIfDisposed();
      return this.m_provider.VerifyHash(hash, hashAlgOid, sig);
    }
  }
}
